package com.kitty.game.task.model.product.targetparam;

import com.kitty.game.task.model.product.TaskTargetParam;
import com.kitty.game.task.model.product.entry.TaskFightEntry;
import org.nutz.json.Json;
import org.nutz.lang.util.NutMap;

import java.util.ArrayList;
import java.util.List;

/**战斗胜利目标参数*/
public class FightWinTargetParam extends TaskTargetParam {
    /**战斗类型为与宠物战斗 */
    public static final byte FIGHT_TO_PET = 1;
    /**战斗类型为与boss战斗*/
    public static final byte FIGHT_TO_BOSS = 2;
    /**战斗类型为与icon、名称、技能指定，其他匹配角色自身属性的战斗*/
    public static final byte FIGHT_TO_MATCHSELF = 3;
    /**战斗类型为与其他门派，用于主线中迷失小孩被绑任务*/
    public static final byte FIGHT_TO_OTHER_SCHOOL = 4;
    /**战斗类型为保护正在飞升的宠物*/
    public static final byte PROTECT_FLYING_PET = 5;


    /**战斗类型*/
    private byte fightTargetType;

    /**战斗对象*/
    private List<TaskFightEntry> fightTarget;

    @Override
    public TaskTargetParam parseParam(NutMap nutMap) {
        this.fightTargetType = (byte)nutMap.getInt("fightType");

        List<TaskFightEntry> fightTarget = nutMap.getAsList("fightTarget", TaskFightEntry.class);
        int fightTargetCount = nutMap.getInt("fightTargetCount", 0);
        if (fightTargetCount > 0) {
            List<TaskFightEntry> newFightTarget = new ArrayList<>(fightTarget.size() * fightTargetCount);
            for (int i=0; i<fightTargetCount; i++) {
                for (TaskFightEntry taskFightEntry : fightTarget) {
                    TaskFightEntry newTaskFightEntry = Json.fromJson(TaskFightEntry.class, Json.toJson(taskFightEntry));
                    newFightTarget.add(newTaskFightEntry);
                }
            }
            this.fightTarget = newFightTarget;
        } else {
            this.fightTarget = fightTarget;
        }

        return this;
    }

    public byte getFightTargetType() {
        return fightTargetType;
    }

    public List<TaskFightEntry> getFightTarget() {
        return fightTarget;
    }
}
